﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using OfficeOpenXml;
using LitTools;
namespace LitTools
{
    [CreateAssetMenu(menuName = "LitExcel/ExcelConverter")]
    public class ExcelConverter : ScriptableObject
    {
        public string excelPath;
        public string sheetName;
        public string csPath;
        public string dataPath;
        public void CreateScript()
        {
            ReadFile();

        }
        public void ReadExcel()
        {
            ReadExcel();
        }

        private void ReadFile()
        {
            if (string.IsNullOrEmpty(excelPath))
                Debug.LogError("excel路径不能为空");
            try
            {
                var fileInfo = new FileInfo(excelPath);
                ReadExcel(fileInfo);
            }
            catch
            {
                Debug.LogError("获取Excel文件失败");
            }
        }

        private void ReadExcel(FileInfo fileInfo)
        {
            using (var package = new ExcelPackage(fileInfo))
            {
                var sheets = package.Workbook.Worksheets;
                for (int i = 0; i < sheets.Count; i++)
                {
                    if (sheets[i].Name == sheetName)
                    {
                        ReadSheet(sheets[i]);
                    }
                }
                Debug.LogError($"表中不存在名为\"<color = red>{sheetName}</color>\"的Sheet");
            }
        }

        private void ReadSheet(ExcelWorksheet sheet)
        {
            //1变量名
            //2变量类型
            //3~变量值
        }
    }
}